package vip.buddha.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import vip.buddha.mapper.StorageMapper;
import vip.buddha.entity.Storage;

@Service
public class StorageService {
    @Autowired
    private StorageMapper storageMapper;

    public Integer updateByGoodsId(Integer goodsId, Storage storage) {
        QueryWrapper<Storage> wrapper = new QueryWrapper<>();
        wrapper.eq("goods_id", goodsId);
        Storage one = storageMapper.selectOne(wrapper);
        if (one.getNum() < storage.getNum()) {
            return 0;
        }
        Storage a = new Storage();
        a.setId(one.getId());
        a.setNum(one.getNum() - storage.getNum());
        return storageMapper.updateById(a);
    }
}
